package com.example.Film.reviews.website.controllers;

import com.example.Film.reviews.website.dao.UserRepository;
import com.example.Film.reviews.website.entities.UserAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("users")
public class UserController {

    @Autowired
    UserRepository userRepository;

    @GetMapping("/new")
    public String displayUserForm(Model model){
        UserAccount aUser = new UserAccount();
        model.addAttribute("user",aUser);
        return "security/register";
    }
        @PostMapping("/save")
        public String createUser(Model model, UserAccount user){
            userRepository.save(user);
            return "redirect:/users";


    }
}
